package com.bdk.controller;


import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdk.mapper.Menu;
import com.bdk.mapper.Role;
import com.bdk.model.MenuVO;
import com.bdk.model.RoleVO;
import com.bdk.service.IMenuService;
import com.bdk.service.IRoleService;

/**
 * 菜单相关操作
 * ClassName: menuController 
 * @Description: 
 * @author ChenQuan
 * @date 2017年5月4日下午1:55:49
 */
@Controller
@RequestMapping("/menu")
public class menuController {
	
	final Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private IMenuService menuService;
	//1、数据列表页面
	@RequestMapping("/menuList.do")
	public String menuList(HttpServletRequest request, MenuVO menuVo, Model model) {
		return "/admin/menu/menuList";
	}
	//2、分页json数据
	@RequestMapping(value = "/getMenuJson.do",produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String getMenuJson(HttpServletRequest request,MenuVO menuVo, Model model) {
		 return menuService.getMenuJson(menuVo);
	}
	//3添加、修改、查看页面
	@RequestMapping("/menupage.do")
	public String menupage(HttpServletRequest request,MenuVO menuVo, Model model) {
		if(menuVo.getPars().equals("add")){
			return "/admin/menu/menuAdd";
		}else if(menuVo.getPars().equals("edit")){
			model.addAttribute("menu", menuService.getMenu(menuVo));
			return "/admin/menu/menuEdit";
		}else{
			model.addAttribute("menu", menuService.getMenu(menuVo));
			return "/admin/menu/menuInfo";
		}
	}
	/**
	 * 4、添加
	 * @param user
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/add.do",produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String add(HttpServletRequest request, MenuVO menuVo) {
	    return menuService.addMenuJson(menuVo,request);
	}
	//5、修改
	@RequestMapping(value="/edit.do",produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String edit(HttpServletRequest request, MenuVO menuVo) {
	     return menuService.updateMenu(menuVo,request);
	}
	/**
	 * 6、删除
	 * 2017年11月4日下午6:40:27
	 * 说明：删除
	 * @param request
	 * @param model
	 * @return String List<User> json 字符串
	 */
	@RequestMapping(value = "/del.do",produces = "text/json;charset=UTF-8")
	@ResponseBody
	public String del(HttpServletRequest request,MenuVO menuVo, Model model) {
		 return menuService.delMenuJson(menuVo.getMenuId());
	}
}
